package com.ipad.net.presenter;

import com.ipad.net.ApiCallback;
import com.ipad.net.ApiClient;
import com.ipad.net.BasePresenter;
import com.ipad.net.apistore.StoreApi;
import com.ipad.net.entity.UpdateEntity;
import com.ipad.net.view.ICheckVersionView;
import com.ipad.utils.MD5Utils;

import io.reactivex.annotations.NonNull;
import io.reactivex.disposables.Disposable;

/**
 * Created by sev-14 on 2018/4/26.
 */

public class CheckVersionPresenter extends BasePresenter<ICheckVersionView> {
    StoreApi apiStore;

    public CheckVersionPresenter() {
        apiStore = ApiClient.getInstance().getpRetorfit().create(StoreApi.class);
    }

    public void checkVersion(String client_type, String version) {
        String data = "{\"client_type\":\""+client_type+"\",\"version_code\":\""+version+"\",\"type\":\""+1+"\"}";
        addSubscribe(apiStore.checkVersion(StoreApi.update_method, data, MD5Utils.getMD5Str(data+ApiClient.app_secret)), new ApiCallback<UpdateEntity>() {

            @Override
            public void onSuccess(UpdateEntity o) {
                t.checkVersion(o);
            }

            @Override
            public void onFailuer(String msg) {
                t.getVersionFail();
            }

            @Override
            public void onFinish() {
                t.stopLoading();
            }
        });
    }

}
